/*
* Copyright 2007 University of Oxford
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// A project represents a single project in the CodeGoo extension
function Project(name, baseURL, id, projectType) {
  try {
    var description = "";
    var shortDescription = "";
    var homepage = "";
    var wiki = "";
    var bugURL = "";
    var mailingListURL = new Array();
    var license = "";
    var downloadURL = "";
    var licenseURL = "";
    var doapxml = "";
    var maintainers = new Array();
    var maintainersURI = new Array();
    var developers = new Array();
    var developersURI = new Array();
    var issues = new Array();
    var atid = "";						
    this.id = id;							// project id used for url in sourceforge	
    this.name = name;                     // project name
    this.baseURL = baseURL;
    this.projectType = projectType;       // "CG" or "SF"
    this.atid = atid;                     // sourceforge atid
    this.issues = issues;                 // object issues
    this.title = name;
    this.doapxml;
    this.description = description;
    this.shortDescription = shortDescription;
    this.homepage = homepage;
    this.wiki = wiki;
    this.bugURL = bugURL;
    this.mailingListURL = mailingListURL;
    this.license = license;
    this.licenseURL = licenseURL;
    this.downloadURL = downloadURL;
    this.maintainers = maintainers;
    this.maintainersURI = maintainersURI;
    this.developers = developers;
    this.developersURI = developersURI;
  } catch (e) {
      alert("error" + e);
    }

  //////////////////////////////////////////////////////////////////////////
  // creates doap xml, works only with Google projects so far!
  //////////////////////////////////////////////////////////////////////////
  this.Xml = function(description, shortDescription, homepage, wiki, bugURL, mailingListURL, licenseURL, license, downloadURL, maintainers, maintainersURI, developers, developersURI) {
    try {
      var doapxml = "";
      var maintainers = new Array();
      //var maintainersURI = new Array();
      var developers = new Array();
      //var developersURI = new Array();
      xmlTag = "<?xml version=\"1.0\"?>";
      xmlnsTag = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"  xmlns=\"http://usefulinc.com/ns/doap#\"  xmlns:foaf=\"http://xmlns.com/foaf/0.1/\">";
      xmlProjectTag = "<Project>"; 
      xmlNameTags = "<name>";
      xmlNameTags += this.title;
      xmlNameTags += "</name>";
      xmlDescription = "<description>" + description + "</description>";
      xmlShortDescription = "<shortdesc>" + shortDescription + "</shortdesc> ";
      xmlHomePage = "<homepage rdf:resource=\"" + homepage +"\"/>";
      xmlWiki = "<wiki rdf:resource=\"" + wiki + "\" />";
      xmlRepository = "<repository>";
  	  xmlRepository += "<SVNRepository>";
      var SVNlocation = "http://" + this.title + ".googlecode.com/svn/";
      var SVNbrowse =  homepage + "/source/browse/";
      xmlRepository += "<location rdf:resource=\"" + SVNlocation + "\"/>";
  	  xmlRepository += "<browse rdf:resource=\"" + SVNbrowse + "\"/>";
      xmlRepository += "</SVNRepository>";
      xmlRepository += "</repository>";
      xmlBugDB = "<bug-database rdf:resource=\"" + bugURL + "\" />";
      xmlMailingList = "";
      for(i=0; i < mailingListURL.length; i++) {
      xmlMailingList += "<mailing-list rdf:resource=\"" + mailingListURL[i] + "\" />";
      }
      xmlLicense = "<license rdf:resource=\"" + licenseURL + "\">" + license + "</license>";
      xmlDownload = "<download-page rdf:resource=\"" + downloadURL + "\" />";
      var xmlMaintainers = "";
      for(i=0; i < maintainersURI.length; i++) {
        xmlMaintainers += "<maintainer>";
        xmlMaintainers += "<foaf:Person rdf:about=\"" + maintainersURI[i] + "\" />";
        //xmlMaintainers += "<foaf:Person><foaf:name>" + maintainers[i] + "</foaf:name></foaf:Person>";
        xmlMaintainers += "</maintainer>";
      }
      var xmlDevelopers = "";
      for(i=0; i < developersURI.length; i++) {
        xmlDevelopers += "<developer>";
        xmlDevelopers += "<foaf:Person rdf:about=\"" + developersURI[i] + "\" />";
        //xmlDevelopers += "<foaf:Person><foaf:name>" + developers[i] + "</foaf:name></foaf:Person>";
        xmlDevelopers += "</developer>";    
      }
      xmlCloseProjectTag = "</Project>";
      xmlnsCloseTag = "</rdf:RDF>";
      doapxml = xmlTag + xmlnsTag + xmlProjectTag + xmlNameTags + xmlDescription + xmlShortDescription;
      doapxml += xmlHomePage + xmlWiki + xmlRepository + xmlBugDB + xmlMailingList + xmlLicense + xmlDownload + xmlMaintainers + xmlDevelopers + xmlCloseProjectTag + xmlnsCloseTag;
      //alert("Here is the DOAP:- \n" + doapxml);
      this.doapxml = doapxml;
      this.description = description;
      this.shortDescription = shortDescription;
      this.homepage = homepage;
      this.wiki = wiki;
      this.bugURL = bugURL;
      this.mailingListURL = mailingListURL;
      this.license = license;
      this.downloadURL = downloadURL;
      this.maintainers = maintainers;
      this.maintainersURI = maintainersURI;
      this.developers = developers;
      this.developersURI = developersURI;
    } catch (e) {
      alert("error" + e);
    }
  }
}